package com.mikufufu.blog.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.common.entity.Query;
import com.mikufufu.blog.model.entity.Tag;
import com.mikufufu.blog.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tag")
@Api(tags = "客户端的标签接口")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/detail")
    @ApiOperation(value = "获取文章标签")
    @ApiImplicitParam(name = "id", value = "标签id", required = true)
    public  AjaxResult<Tag> detail(Integer id) {
        return AjaxResult.data(tagService.getById(id));
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页获取文章标签列表")
    @ApiImplicitParam(name = "tagType", value = "标签类型（0.文章标签,1.相册标签）", required = true)
    public AjaxResult<IPage<Tag>> page(Query query,Integer tagType) {
        return AjaxResult.data(tagService.page(query.getPage(),new LambdaQueryWrapper<Tag>().eq(tagType!=null ,Tag::getTagType, tagType)));
    }

}
